/**
 * Created by Administrator on 2016/6/14.
 */
//切换发起接到窗口、首页菜单栏切换
$("document").ready(function(){
    $("nav section a").click(function(){
        $("nav section a").removeClass().addClass("unFocus");
        $(this).addClass("focus");
    });
    $(".filter a").click(function(){
        $(".filter a").removeClass();
        $(this).addClass("active");
    });
})
//菜单固定在底部
$(document).ready(function(){
    var $width = $(window).width();
    var $height   = $(window).height();
    $(".mask").css({'height':$height+200,'width':$width});
});

//公共变量设置
var session_id = sessionStorage.session_id;
var u_id = sessionStorage.u_id;
var user_token = sessionStorage.user_token;
var type = "all";
sessionStorage.type = "all";
var check_type;
var page = 1;
//请求用户类型
var isDoctor;


//订单列表模板
var order = '<section class="items" v-for="item in items"><section class="order" v-if="item.status == \'2\'&&item.check_type==\'1\'"><section><img src="../images/wenzhen_faqi.png"><span class="time">发起时间:{{item.create_time|wrap}}</span><span>状态：{{item.status_name}}</span></section><section><img v-if="item.doctor_info.nic_thumb != \'\'" v-bind:src="item.doctor_info.nic_thumb" /><img v-if="item.doctor_info.nic_thumb ==\'\'" src="../images/userDefault.png" /><section><p>{{item.doctor_info.name}} {{item.doctor_info.zhiwu}}</p><p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</span></p></section><section> </section> </section> <section> <p class="orderInfo">{{item.tips}}</p> <p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order payment" v-if="item.status == \'6\'&&item.check_type==\'1\'"> <section><img src="../images/wenzhen_faqi.png"> <span class="time">发起时间:{{item.create_time|wrap}}</span><span>状态：{{item.status_name}}</span> </section><section><img v-if="item.doctor_info.nic_thumb != \'\'" v-bind:src="item.doctor_info.nic_thumb" /><img v-if="item.doctor_info.nic_thumb ==\'\'" src="../images/userDefault.png" /><section><p>{{item.doctor_info.name}} {{item.doctor_info.zhiwu}}</p><p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</span></p></section><section> ' + '<img v-if="item.if_call == \'0\'" src="../images/callDoctorW.png" class="callDoctor"> <img src="../images/consultCompleteW.png" class="consultComplete"><img src="../images/callContinueW.png" v-if="item.if_call == \'1\'" class="callContinue"><span class="doctor_tel">{{item.doctor_info.tel}}</span> <span class="user_tel">{{item.user_info.tel}}</span> </section> </section> <section> <p class="orderInfo">{{item.tips}}</p><p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p> <p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order payment" v-if="item.status == \'7\'&&item.check_type==\'1\'"> <section> <img src="../images/wenzhen_faqi.png"><span class="time">发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section> <img v-if="item.doctor_info.nic_thumb != \'\'" v-bind:src="item.doctor_info.nic_thumb" /> <img v-if="item.doctor_info.nic_thumb ==\'\'" src="../images/userDefault.png" /> <section> <p>{{item.doctor_info.name}} {{item.doctor_info.zhiwu}}</p> <p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</span></p> </section> <section> <img src="../images/comment1W.png" class="comment1"></section> </section> <section> <p class="orderInfo">{{item.tips}}</p><p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p> <p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order payment" v-if="item.status == \'8\'&&item.check_type==\'1\'"> <section><img src="../images/wenzhen_faqi.png"> <span class="time">发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section> <img v-if="item.doctor_info.nic_thumb != \'\'" v-bind:src="item.doctor_info.nic_thumb" /> <img v-if="item.doctor_info.nic_thumb ==\'\'" src="../images/userDefault.png" /> <section> <p>{{item.doctor_info.name}} {{item.doctor_info.zhiwu}}</p> <p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</span></p> </section><section>  <img src="../images/writeDairyW.png" class="writeDairy"> </section> </section> <section> <p class="orderInfo">{{item.tips}}</p> <p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order" v-if="item.status == \'2\'&&item.check_type==\'2\'"> <section> <img src="../images/wenzhen_jieshou.png"><span class="time">发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section> <img v-if="item.user_info.nic_thumb != \'\'" v-bind:src="+item.user_info.nic_thumb" /> <img v-if="item.user_info.nic_thumb ==\'\'" src="../images/userDefault.png" /> <section> <p>{{item.user_info.name}}</p> <p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</p> </section> <section>  </section> </section> <section> <p class="orderInfo">{{item.tips}}</p> <p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order payment" v-if="item.status == \'6\'&&item.check_type==\'2\'"> <section> <img src="../images/wenzhen_jieshou.png"><span class="time" >发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section><img v-if="item.user_info.nic_thumb != \'\'" v-bind:src="item.user_info.nic_thumb" /><img v-if="item.user_info.nic_thumb ==\'\'" src="../images/userDefault.png" /><section><p>{{item.user_info.name}}</p><p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</p></section><section> <img src="../images/callUserW.png" id="call" class="callUser"> </section> </section> <section> <p class="orderInfo">{{item.tips}}</p> <p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> <span class="doctor_tel">{{item.doctor_info.tel}}</span> <span class="user_tel">{{item.user_info.tel}}</span> </section><section class="order" v-if="item.status == \'7\'&&item.check_type==\'2\'"> <section><img src="../images/wenzhen_jieshou.png"> <span class="time">发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section> <img v-if="item.user_info.nic_thumb != \'\'" v-bind:src="item.user_info.nic_thumb" /> <img v-if="item.user_info.nic_thumb ==\'\'" src="../images/userDefault.png" /> <section> <p>{{item.user_info.name}}</p> <p>电话咨询 <span class="price">￥{{item.doctor_info.price|wra}}/分钟</p> </section> <section>  </section> </section> <section> <p class="orderInfo">{{item.tips}}</p><p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p> <p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section> <section class="order" v-if="item.status == \'8\'&&item.check_type==\'2\'"> <section> <img src="../images/wenzhen_jieshou.png"><span class="time">发起时间:{{item.create_time|wrap}}</span> <span>状态：{{item.status_name}}</span> </section> <section> <img v-if="item.user_info.nic_thumb != \'\'" v-bind:src="item.user_info.nic_thumb" /> <img v-if="item.user_info.nic_thumb ==\'\'" src="../images/userDefault.png" /> <section> <p>{{item.user_info.name}}</p> <p>电话咨询<span class="price">￥{{item.doctor_info.price|wra}}/分钟</p> </section> <section>  </section> </section> <section> <p class="orderInfo">{{item.tips}}</p> <p class="order_num">{{item.order_num}}</p><p class="name">{{item.doctor_info.name}}</p><p class="user_nic_name">{{item.user_info.name}}</p><p class="d_id">{{item.doctor_info.d_id}}</p><p class="check_type">{{item.check_type}}</p></section> </section></section>';

//切换发起接到窗口数据请求
$("document").ready(function(){
    $(".filter a").click(function(){
        $("#consultList").empty();
        var index =$(this).index();
        switch(index){
            case 0:
                type = "all";
                sessionStorage.type = "all";
                break;
            case 1:
                type = "todo";
                sessionStorage.type = "todo";
                break;
            case 2:
                type = "completed";
                sessionStorage.type = "completed";
                break;
            case 3:
                type = "cancel";
                sessionStorage.type = "cancel";
                break;
        }
        ajaxOrderDefault();
    })
})

//订单分类数据请求
$("document").ready(function(){

    $("nav section a:first-child").click(function(){
        $("#consultList").empty();
        ajaxOrderDefault();
    })
    $("nav section a:last-child").click(function(){
        $("#consultList").empty();
        ajaxOrderDefault();
    })
})
//定义默认获取数据方法
$(document).ready(
     ajaxOrderDefault = function(){
         $(".filter img").css("display","none");
         $.ajaxSettings.async=false;
    $.post(commonval+"/order_list",{
        check_type:check_type,
        u_id:u_id,
        user_token:user_token,
        device:"wap",
        type:sessionStorage.type,
        page:page,
        session_id:session_id
    },function(data){
        if(data.status == 1){
            $("footer").css("display","block");
            if(data.data == ''){
                switch (sessionStorage.type) {
                    case "all":
                        $("#consultList").append(' <section class="Tips"><img src="../images/orderGirl.png" /><p>你还没有向医生咨询过？首次咨询有优惠哦</p> <button>立即咨询</button></section>');
                        break;
                    case "todo":
                        $("#consultList").append(' <section class="Tips"><img src="../images/orderGirl.png" /><p>没有待处理的订单。</p> </section>');
                        break;
                    case "completed":
                        $("#consultList").append(' <section class="Tips"><img src="../images/orderGirl.png"/><p>没有已完成的订单。</p> </section>');
                        break;
                    case "cancel":
                        $("#consultList").append(' <section class="Tips"><img src="../images/orderGirl.png" /><p>没有已取消的订单。</p> </section>');
                        break;
                }
                $.ajaxSettings.async=false;
                var u_id = sessionStorage.u_id;
                var check_type = sessionStorage.check_type;
                $.post(commonval+"/PendingOrder",{
                    u_id:u_id,
                    user_token:user_token,
                    device:"wap",
                    session_id:session_id
                },function(data){
                    if(data.status == 1){
                        if(data.data.wait_order == 1){
                            $(".filter img").css("display","inline");
                        }
                    }
                })
               $("section.Tips button").click(function(){
                   location.href="doctorList.html";
               })
            }else{
                var status = data.data.status;
                var type = data.data.type;
                var check_type = sessionStorage.check_type;
                //vue模板
                $("#consultList").append(order);
                $(".filter").css("display","block");
                Vue.filter('wrap', function (value) {
                    return value.substr(0, 10);
                })
                Vue.filter('wra', function (value) {
                    return value/100;
                })
                var consultList = new Vue({
                    el: '#consultList',
                    data: {
                        items: data.data
                    }
                });

                var u_id = sessionStorage.u_id;
                $.post(commonval+"/user_info",{
                    u_id:u_id,
                    user_token:user_token,
                    device:"wap",
                    session_id:session_id
                },function(data){
                    if(data.data.isDoctor == 1){
                        $("section.order section:first-child img").css("display","block");
                        $("section.order section:first-child span").css("margin-left","3%");
                    }
                })
                //////时间处理
                ////var dataUse = data.data;
                //////for(var i=0;i<dataUse.length;i++){
                //////    var create_time = dataUse[i].create_time;
                //////    create_time = create_time.substr(0, 10);
                //////    var j =10*page+i;
                //////    $(".time").eq(j).text("发起时间："+create_time);
                //////    //$(".items").eq(i).children(".time").text("发起时间："+create_time);
                //////    ////console.log($(".items").eq(i).children(".order").children(".time").text());
                //////    //console.log($(".time").eq(i).text());
                //////}
                ////价格处理
                //for(var i=0;i<dataUse.length;i++){
                //    var price = dataUse[i].doctor_info.price;
                //    price = price/100;
                //    $(".price").eq(i).text("￥"+price+"/分钟");
                //    //$(".items").eq(i).children(".time").text("发起时间："+create_time);
                //    ////console.log($(".items").eq(i).children(".order").children(".time").text());
                //    //console.log($(".time").eq(i).text());
                //}
                //待处理通知

                $.ajaxSettings.async=false;
                var u_id = sessionStorage.u_id;
                var check_type = sessionStorage.check_type;
                $.post(commonval+"/PendingOrder",{
                    u_id:u_id,
                    user_token:user_token,
                    device:"wap",
                    session_id:session_id
                },function(data){
                    if(data.status == 1){
                        if(data.data.wait_order == 1){
                            $(".filter img").css("display","inline");
                        }
                    }
                })
                var url ="order.html";
                $("section.order").click(function(){
                    console.log(order_num);
                    var order_num = $(this).children("section:nth-child(3)").children(".order_num").text();
                    var check_type = $(this).children("section:nth-child(3)").children("p.check_type").text();
                    location.href = url+"?order_num="+order_num;
                    sessionStorage.check_type = check_type;

                });
                //初次打电话
                $("section.order .callDoctor").click(function(e){
                    //$(this).attr("src","../images/callDoctorB.png");
                    var docName = $(this).parents(".order.payment").children("p.name").text();
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    var doctor_tel = $(this).parent().children("span.doctor_tel").text();
                    var user_tel = $(this).parent().children("span.user_tel").text();
                    $.ajaxSettings.async = false;
                    $.post(commonval+"/callBack", {
                        user_token:user_token,
                        device:"wap",
                        order_num: order_num,
                        from: user_tel,
                        to: doctor_tel,
                        session_id:session_id
                    }, function (data) {
                        if (data.status == 1) {
                            if(data.data.type ==3){
                                createWindow1("帮您呼叫中……");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/callBeing.gif'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }else if(data.data.type ==2){
                                createWindow1("由于网络问题，联系失败,请稍后重试。");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/webFailed.png'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }
                        } else if (data.status == 0) {
                            createWindow1("由于网络问题，联系失败,请稍后重试。");
                            function createWindow1(msg) {
                                $(".mask").click(function(){
                                    $(".mask").css({'display':'none'});
                                    $('.showMsg1').remove();
                                })
                                $('.mask').css({'display':'block'});
                                var window =$("<section class='showMsg1'></section>");
                                var img = "<img src='../images/webFailed.png'>";
                                var show = "<p>"+msg+"</p>";
                                window.append(img);
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg1').remove()",5000);
                                setTimeout("$('.mask').css({'display':'none'})",5000);
                            }
                        }
                    });
                    e.stopPropagation();
                });

                //联系用户
                $("section.order .callUser").click(function(e){
                    var docName = $(this).parents(".order.payment").children("p.name").text();
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    var doctor_tel = $(this).parents(".order.payment").children("span.doctor_tel").text();
                    var user_tel = $(this).parents(".order.payment").children("span.user_tel").text();
                    var user_nic_name = $(this).parents(".order.payment").children("span.user_nic_name").text();
                    console.log(order_num,doctor_tel,user_tel,user_nic_name);
                    $.ajaxSettings.async = false;
                    $.post(commonval+"/callBack", {
                        user_token:user_token,
                        device:"wap",
                        order_num: order_num,
                        from: doctor_tel,
                        to: user_tel,
                        session_id:session_id
                    }, function (data) {
                        if (data.status == 1) {
                            if(data.data.type ==3){
                                createWindow1("帮您呼叫中……");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/callBeing.gif'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }else if(data.data.type ==2){
                                createWindow1("由于网络问题，联系失败,请稍后重试。");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/webFailed.png'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }else if(data.data.type ==3){
                                var $width = $(window).width();
                                var $height = $(window).height();
                                $(".mask").css({'height':$height,'width':$width,'display':'inherit'});
                                $('.toast').css({'display':'inherit','position':'absolute','top':($height-490)/2,'left':'15%','z-index':'200'});
                                $('.toast p:nth-child(2)').click(function(){
                                    $('.toast').css('display','none');
                                    $('.mask').css('display','none');
                                })
                            }
                        } else if (data.status == 0) {
                            createWindow(data.msg);
                            function createWindow(msg) {
                                var window =$("<section class='showMsg'></section>");
                                var show = "<p>"+msg+"</p>";
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg').remove()",3000);
                            }
                            //var url = "orderPay.html";
                            //var order_num = $(this).parents(".order").children("p.order_num").text();
                            //location.href = url+"?order_num="+order_num;
                        }

                    });
                    e.stopPropagation();
                });
                //写日记逻辑
                $(".writeDairy").click(function(e){
                    var url = "writeDairy.html";
                    var d_id = $(this).parents(".order.payment").children("p.d_id").text();
                    sessionStorage.dairyDID = d_id;
                    var order_num = $(this).parents(".order").children("p.order_num").text();
                    location.href = url+"?order_num="+order_num;
                    e.stopPropagation();
                });

                $(".payImmediate").click(function(e){
                    var url = "pay.html";
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    location.href = url+"?order_num="+order_num;
                    e.stopPropagation();
                });
                //评论逻辑
                $(".comment1").click(function(e){
                    e.stopPropagation();
                    $(".mask").css("display","block");
                    $(".comment").css("display","block");
                    var check_type = sessionStorage.check_type;
                    console.log(check_type);
                    $.ajaxSettings.async=false;
                    $.post(commonval+"/order_comment",{
                        user_token:user_token,
                        device:"wap",
                        order_num:order_num,
                        check_type:check_type,
                        session_id:session_id
                    },function(data){
                    })
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    console.log(order_num);
                    sessionStorage.corder_num = order_num;

                });
                $(".comment .thirdPart button:first-child").click(function(){
                    $(".mask").css("display","none");
                    $(".comment").css("display","none");
                })
                $(".comment .thirdPart button:last-child").click(function(){
                    var grade = $(".comment .firstPart span:nth-child(3)").text().replace("分","");
                    if(grade == 0){
                        createWindow("请为医生服务打分");
                        function createWindow(msg) {
                            var window =$("<section class='showMsg'></section>");
                            var show = "<p>"+msg+"</p>";
                            window.append(show);
                            $("body").append(window);
                            setTimeout("$('.showMsg').remove()",3000);
                        }
                    }


                })

                //继续联系逻辑
                $(".callContinue").click(function(e){
                    //$(this).attr("src","../images/callContinueB.png");
                    var docName = $(this).parents(".order.payment").children("p.name").text();
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    var doctor_tel = $(this).parent().children("span.doctor_tel").text();
                    var user_tel = $(this).parent().children("span.user_tel").text();
                    $.ajaxSettings.async = false;
                    $.post(commonval+"/callBack", {
                        user_token:user_token,
                        device:"wap",
                        order_num: order_num,
                        from:user_tel ,
                        to: doctor_tel,
                        session_id:session_id
                    }, function (data) {
                        if (data.status == 1) {
                            if(data.data.type == 3){
                                createWindow1("帮您呼叫中……");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/callBeing.gif'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }else if(data.data.type == 1){
                                sessionStorage.call_time =data.data.call_time;
                                $('.go_or_not p:first-child').text("为保证咨询质量，您还需要购买至少"+sessionStorage.call_time+"分钟的咨询时长")
                                var $width = $(window).width();
                                var $height = $(window).height();
                                $(".mask").css({'height':$height,'width':$width,'display':'inherit'});
                                $('.go_or_not').css({'display':'inherit','position':'absolute','top':($height-220)/2,'left':'15%','z-index':'200'});
                                $('.go_or_not p:nth-child(2)').click(function(){
                                    $('.go_or_not').css('display','none');
                                    $('.mask').css('display','none');
                                })
                                $('.go_or_not p:nth-child(3)').click(function(){
                                    var url = "orderPay.html";
                                    location.href = url+"?order_num="+order_num;
                                })
                            }else if(data.data.type == 2){
                                createWindow1("由于网络问题，联系失败,请稍后重试。");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/webFailed.png'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }else{
                                createWindow1("由于网络问题，联系失败,请稍后重试。");
                                function createWindow1(msg) {
                                    $(".mask").click(function(){
                                        $(".mask").css({'display':'none'});
                                        $('.showMsg1').remove();
                                    })
                                    $('.mask').css({'display':'block'});
                                    var window =$("<section class='showMsg1'></section>");
                                    var img = "<img src='../images/webFailed.png'>";
                                    var show = "<p>"+msg+"</p>";
                                    window.append(img);
                                    window.append(show);
                                    $("body").append(window);
                                    setTimeout("$('.showMsg1').remove()",5000);
                                    setTimeout("$('.mask').css({'display':'none'})",5000);
                                }
                            }

                        } else if (data.status == 0) {
                            createWindow1("由于网络问题，联系失败,请稍后重试。");
                            function createWindow1(msg) {
                                $(".mask").click(function(){
                                    $(".mask").css({'display':'none'});
                                    $('.showMsg1').remove();
                                })
                                $('.mask').css({'display':'block'});
                                var window =$("<section class='showMsg1'></section>");
                                var img = "<img src='../images/webFailed.png'>";
                                var show = "<p>"+msg+"</p>";
                                window.append(img);
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg1').remove()",5000);
                                setTimeout("$('.mask').css({'display':'none'})",5000);
                            }
                        }
                    })
                    e.stopPropagation();
                });
            //.
                //订单完成逻辑
                $(".consultComplete").click(function(e){
                    //$(this).attr("src","../images/consultCompleteB.png");
                    e.stopPropagation();
                    //请求是否小于一分钟
                    var name = $(this).parent().parent().parent().children("span.name").text();
                    var order_num = $(this).parent().parent().parent().children("section:nth-child(3)").children("p.order_num").text();
                    $.post(commonval+"/order_one_minute", {
                        user_token:user_token,
                        device:"wap",
                        order_num: order_num,
                        session_id:session_id
                    }, function (data) {
                        if(data.status ==1){
                            if(data.data.if_over_one_minute == 1){
                                $('.go_or_not2 p:first-child').text(data.data.msg);
                                $('.go_or_not2 p:nth-child(3)').click(function(){
                                    var url = "consult.html";
                                    e.stopPropagation();
                                    $.post(commonval+"/order_sure", {
                                        user_token:user_token,
                                        device:"wap",
                                        order_num: order_num,
                                        session_id:session_id
                                    }, function (data) {
                                        console.log(data.msg);
                                        if(data.status ==1){
                                            if(data.data.type == 1){
                                                $('.go_or_not2').css("display","none");
                                                $(".mask").css("display","block");
                                                $(".comment").css("display","block");
                                                var check_type = sessionStorage.check_type;
                                                console.log(check_type);
                                                $.ajaxSettings.async=false;
                                                $.post(commonval+"/order_comment",{
                                                    user_token:user_token,
                                                    device:"wap",
                                                    order_num:order_num,
                                                    check_type:check_type,
                                                    session_id:session_id
                                                },function(data){
                                                    sessionStorage.corder_num = order_num;
                                                    location.reload(true);
                                                })
                                            }else{
                                                $('.go_or_not2').css("display","none");
                                                $(".mask").css("display","none");
                                                createWindow(data.data.msg);
                                                function createWindow(msg) {
                                                    var window =$("<section class='showMsg'></section>");
                                                    var show = "<p>"+msg+"</p>";
                                                    window.append(show);
                                                    $("body").append(window);
                                                    setTimeout("$('.showMsg').remove()",3000);
                                                }
                                            }
                                        }else{
                                            createWindow(data.msg);
                                            function createWindow(msg) {
                                                var window =$("<section class='showMsg'></section>");
                                                var show = "<p>"+msg+"</p>";
                                                window.append(show);
                                                $("body").append(window);
                                                setTimeout("$('.showMsg').remove()",3000);
                                            }
                                        }
                                    });
                                });
                            }else if(data.data.if_over_one_minute == 0){
                                $('.go_or_not2 p:first-child').text(data.data.msg);
                                $('.go_or_not2 p:nth-child(3)').click(function(){
                                    $(".mask").css("display","none");
                                    $(".go_or_not2").css("display","none");
                                    $.post(commonval+"/order_sure", {
                                        user_token:user_token,
                                        device:"wap",
                                        order_num: order_num,
                                        session_id:session_id
                                    }, function (data) {
                                        if(data.status ==1){
                                            if(data.data.type == 1){
                                                createWindow("订单取消成功");
                                                function createWindow(msg) {
                                                    var window =$("<section class='showMsg'></section>");
                                                    var show = "<p>"+msg+"</p>";
                                                    window.append(show);
                                                    $("body").append(window);
                                                    setTimeout("$('.showMsg').remove()",3000);
                                                }
                                                location.reload(true);
                                            }else{
                                                $('.go_or_not2').css("display","none");
                                                $(".mask").css("display","none");
                                                createWindow(data.data.msg);
                                                function createWindow(msg) {
                                                    var window =$("<section class='showMsg'></section>");
                                                    var show = "<p>"+msg+"</p>";
                                                    window.append(show);
                                                    $("body").append(window);
                                                    setTimeout("$('.showMsg').remove()",3000);
                                                }
                                            }
                                            //location.reload(true);
                                        }else{
                                            createWindow(data.msg);
                                            function createWindow(msg) {
                                                var window =$("<section class='showMsg'></section>");
                                                var show = "<p>"+msg+"</p>";
                                                window.append(show);
                                                $("body").append(window);
                                                setTimeout("$('.showMsg').remove()",3000);
                                            }
                                        }

                                    });

                                });

                            }
                        }else{
                            createWindow(data.msg);
                            $(".mask").css("display","none");
                            function createWindow(msg) {
                                var window =$("<section class='showMsg'></section>");
                                var show = "<p>"+msg+"</p>";
                                window.append(show);
                                $("body").append(window);
                                setTimeout("$('.showMsg').remove()",3000);
                            }
                        }
                    });
                    //调用窗口
                    var $width = $(window).width();
                    var $height   = $(window).height();
                    $(".mask").css({'display':'inherit'});
                    $('.go_or_not2').css({'display':'inherit','position':'absolute','top':($height-400)/2,'left':'15%','z-index':'200'});
                    $('.go_or_not2 p:nth-child(2)').click(function(){
                        $('.go_or_not2').css('display','none');
                        $('.mask').css('display','none');
                    })
                    //完成订单事件
                });
            }
        }else{
            if(data.msg=="非法请求"){
                createWindow("登录失效，正在跳转至登录界面");
                function createWindow(msg) {
                    var window =$("<section class='showMsg'></section>");
                    var show = "<p>"+msg+"</p>";
                    window.append(show);
                    $("body").append(window);
                    setTimeout("$('.showMsg').remove()",3000);
                }
                setTimeout(function(){location.href="register.html?jump=2"},4000);
            }
        }
    });
});
$(document).ready(function(){
    //星星点评逻辑
    $(".comment input").click(function(){
        sessionStorage.value = value;
        var value = $(".comment input:checked").val();
        $("this").next().css("color","#ffb400");
        var span = $(".comment .firstPart span:nth-child(3)");
        switch (value){
            case "half":
                span.text("1分");
                break;
            case "1":
                span.text("2分");
                break;
            case "1 and a half":
                span.text("3分");
                break;
            case "2":
                span.text("4分");
                break;
            case "2 and a half":
                span.text("5分");
                break;
            case "3":
                span.text("6分");
                break;
            case "3 and a half":
                span.text("7分");
                break;
            case "4":
                span.text("8分");
                break;
            case "4 and a half":
                span.text("9分");
                break;
            case "5":
                span.text("10分");
                break;

        }
    })

    $(".comment .thirdPart button:first-child").click(function(){
        $(".mask").css("display","none");
        $(".comment").css("display","none");
        location.reload(true);
    })
    $(".comment .thirdPart button:last-child").click(function(){
        var order_num = sessionStorage.corder_num;
        var value = $(".comment input:checked").val();
        console.log(value);
        var grade = $(".comment .firstPart span:nth-child(3)").text().replace("分","");
        var text = $(".comment textarea").val();
        if(grade == 0){
            createWindow("请为医生服务打分");
            function createWindow(msg) {
                var window =$("<section class='showMsg'></section>");
                var show = "<p>"+msg+"</p>";
                window.append(show);
                $("body").append(window);
                setTimeout("$('.showMsg').remove()",3000);
            }
        }else{
            if(text==''){
                createWindow("请输入服务评语");
            }else if(text.length<20||text.length>200){
                createWindow("服务评语在20-200字之间");
            }else{
                $.ajaxSettings.async=false;
                $.post(commonval+"/order_comment",{
                    user_token:user_token,
                    device:"wap",
                    order_num:order_num,
                    comment:text,
                    score:grade,
                    session_id:session_id
                },function(data){
                    if(data.status ==1){
                        $(".mask").css("display","none");
                        $(".comment").css("display","none");
                        history.go(0);
                        createWindow("订单评价成功");
                    }else{
                        createWindow(data.msg);
                    }
                })
            }
        }
    })
});
var page  = 1;
//自定义vue模板
var loading = false;
//分页
$(document).ready(function(){
    $("#consultList").scroll(function(){
        if (loading)
        {
            return;
        }
        if  ($(window).scrollTop() > $(document).height() - $(window).height() - 200)
        {
            loading = true;
            setTimeout(function(){
                nextPage() ;
            }, 250);
        }
    });
});


nextPage = function(){
    console.log($("#consultList .items").length==page*10);
    if($("#consultList .items").length==page*10){
        page++;
        ajaxOrderDefault();
    }
}





